//
//  SettleManageTimeVM.swift
//  kxf
//
//  Created by Elavatine on 2024/10/13.
//


import Foundation
import UIKit

class SettleManageTimeVM: UIView {
    
    var selfHeight = RegisterViewHeadTitleVM().selfHeight+kFitWidth(300)
    var hourTimeArray = NSMutableArray()
    var minutTimeArray = NSMutableArray()
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initTimeArray()
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var photoTitleVm : RegisterViewHeadTitleVM = {
        let vm = RegisterViewHeadTitleVM.init(frame: CGRect.init(x: 0, y: 0, width: 0, height: 0))
        vm.titleLabel.text = "结算时间"
        return vm
    }()
    lazy var timePickerView: UIPickerView = {
        let picker = UIPickerView.init(frame: CGRect.init(x: 0, y: self.photoTitleVm.frame.maxY, width: SCREEN_WIDHT, height: kFitWidth(250)))
        picker.delegate = self
        picker.dataSource = self
        return picker
    }()
}

extension SettleManageTimeVM{
    func initUI() {
        addSubview(photoTitleVm)
        addSubview(timePickerView)
        
        timePickerView.selectRow(8, inComponent: 0, animated: false)
        timePickerView.selectRow(30, inComponent: 1, animated: false)
    }
    
    func initTimeArray() {
        for i in 0..<24{
            if i < 10{
                hourTimeArray.add("0\(i)")
            }else{
                hourTimeArray.add("\(i)")
            }
        }
        for i in 0..<60{
            if i < 10{
                minutTimeArray.add("0\(i)")
            }else{
                minutTimeArray.add("\(i)")
            }
        }
    }
}

extension SettleManageTimeVM:UIPickerViewDelegate,UIPickerViewDataSource{
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 2
    }
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if component == 0 {
            return hourTimeArray.count
        }else{
            return minutTimeArray.count
        }
    }
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        if component == 0 {
            return "\(hourTimeArray[row])"
        }else{
            return "\(minutTimeArray[row])"
        }
    }
}
